#pragma once 


#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include<bits/socket.h>
#include<string>
#include<iostream>
#include<cstring>
#include<sstream>
#include<memory>


namespace tmms
{
    namespace network
    {
       class InetAddress
       {
        public:
            InetAddress(const std::string &ip,uint16_t port,bool bv6 = false);
            InetAddress() = default;
            InetAddress(const std::string &host,bool is_v6 = false);

            ~InetAddress() = default;

            void SetHost(const std::string &host);
            void SetAddr(const std::string &in_addr);
            void SetPort(uint16_t port);
            void SetIsIPV6(bool is_v6);

            const std::string &IP() const;
            uint32_t IPV4(const char* ip)const;
            std::string ToIpPort()const;
            uint16_t Port() const;
            void GetSockAddr(struct sockaddr *saddr) const;

            bool IsIpV6() const ;
            bool IsWanIp()const ;
            bool IsLanIp () const;
            bool IsLoopbackIp() const;

            void GetIpAndPort(const std::string &host,std::string &ip,std::string &port);//从host地址中解析出ip和port

        private:
            uint32_t IPV4()const;

            std::string addr_;
            std::string port_;
            bool is_ipv6_;

       };
       using InetAddressPtr = std::shared_ptr<InetAddress>; // 定义智能指针别名 
    } 
}